﻿using OpenSage.Data.Ini;

namespace OpenSage.Logic.Object;

internal sealed class RadarUpgrade : UpgradeModule
{
    internal RadarUpgrade(GameObject gameObject, IGameEngine gameEngine, RadarUpgradeModuleData moduleData)
        : base(gameObject, gameEngine, moduleData)
    {
    }

    internal override void Load(StatePersister reader)
    {
        reader.PersistVersion(1);

        reader.BeginObject("Base");
        base.Load(reader);
        reader.EndObject();
    }
}

/// <summary>
/// Triggers use of <see cref="RadarUpdateModuleData"/> module on this object if present and enables the
/// Radar in the command bar.
/// </summary>
public sealed class RadarUpgradeModuleData : UpgradeModuleData
{
    internal static RadarUpgradeModuleData Parse(IniParser parser) => parser.ParseBlock(FieldParseTable);

    private static new readonly IniParseTable<RadarUpgradeModuleData> FieldParseTable = UpgradeModuleData.FieldParseTable
        .Concat(new IniParseTable<RadarUpgradeModuleData>
        {
            { "DisableProof", (parser, x) => x.DisableProof = parser.ParseBoolean() }
        });

    public bool DisableProof { get; private set; }

    internal override BehaviorModule CreateModule(GameObject gameObject, IGameEngine gameEngine)
    {
        return new RadarUpgrade(gameObject, gameEngine, this);
    }
}
